﻿/// <reference path="references.js" />
if ( !window.Gorbatras ) window.Gorbatras = {};
if ( !window.Gorbatras.Admin ) window.Gorbatras.Admin = {};
//The modules
$.getScript( "../js/textureSelection.js", function () { Gorbatras.Admin.TextureSelection.Init(); } );
$.getScript( "../js/filecontrol.js" );

Gorbatras.Admin.AddModel = {};

//Handles name & output path so they are the same if you type anything in name tag
Gorbatras.Admin.AddModel.HandleNameOutput = function ()
{
    $_name = $( "#x_name" );
    $_output = $( "#x_outputPath" );

    //This function does not work if user edited in the middle
    $_name.keypress( function ( e )
    {
        var f_name = $_name.val(),
            f_output = $_output.val();

        if ( f_name === f_output )
        {
            //Backspace
            if ( e.keyCode === 8 )
            {
                if ( f_output !== "" )
                {
                    //Tried to get caret/cursor code but it bugged kinda... returning 0 which messed everything up
                    $_output.val( f_output.substring( 0, f_output.length - 1 ) );
                }
            }
            else
            {
                //0 is some <?> stuff!
                if ( e.charCode !== 0 )
                {
                    $_output.val( f_output + String.fromCharCode( e.charCode ) );
                }
            }
        }

    } );
};

Gorbatras.Admin.AddModel.UpdateInput = function ( a_inputFile, a_inputPanel, a_inputLabel )
{    
    $_file = $( a_inputFile );
    $_panel = $( a_inputPanel );
    $_label = $( a_inputLabel );
    
    if ( $_file.val() && $_file.val() !== "" )
    {
        $_panel.show( 0 );
        $_label.text( $_file.val() );
    }
};

$( document ).ready( function ()
{       
    Gorbatras.Admin.AddModel.HandleNameOutput();
} );